﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace _15puzzle
{
    class Program
    {
        static void Main(string[] args)
        {
            bool exit = false;
            while (!exit)
            {
                Game Game = new Game();
                Game.Randomize();
                Game.PaintBoard();
                ConsoleKeyInfo PressedKey;
                int Moves = 0;

                while (Game.CheckBoard() != true)
                {
                    PressedKey = Console.ReadKey();
                    Game.Move(PressedKey.Key.ToString());
                    Game.PaintBoard();
                    Moves++;
                    Game.CheckBoard();
                }

                Console.SetCursorPosition(0, 10);
                Console.WriteLine("Grattis, du löste pusslet!\n");
                Console.WriteLine("Ville du spela igen? Ja/nej. \n");
                string s = Console.ReadLine();

                if (s == "ja")
                {
                    exit = false;
                }
                else if (s == "nej")
                {
                    Console.WriteLine("OK, avslutar spel...");
                    exit = true;
                    Thread.Sleep(2000);
                }
            }
        }
    }
}
